#ifndef ICEMANAGER_H
#define ICEMANAGER_H

#include "nice/nice.h"
#include "iceserver.h"
#include "icestream.h"
#include <iostream>
#include <vector>
#include <pthread.h>

class ICEManager
{
public:
    ICEManager();
    ~ICEManager();
    void initialise( ICEServer *stun_server, ICEServer *turn_server = NULL );
    void release();
    ICEStream *createStream( guint n_component = 1 );

private:
    std::vector<ICEStream*> streams;
    NiceAgent *agent;
    GMainLoop *global_mainloop;
    ICEServer *stun_server;
    ICEServer *turn_server;
    pthread_t global_mainloop_thread;

    static void cb_candidate_gathering_done( NiceAgent *agent, guint stream_id, gpointer user_data );
    static void cb_new_selected_pair( NiceAgent *agent, guint stream_id, guint component_id,
                                      gchar *lfoundation, gchar *rfoundation, gpointer user_data );
    static void cb_nice_recv( NiceAgent *agent, guint stream_id, guint component_id,
                              guint len, gchar *buf, gpointer user_data );
};

#endif // ICEMANAGER_H
